package com.woniuxy.userapp.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.userapp.common.exception.Myexception.UserException;
import com.woniuxy.userapp.common.exception.code.UserExceptionCode;
import com.woniuxy.userapp.infra.model.mapper.VenueMapper;
import com.woniuxy.userapp.infra.model.mapper.model.FrontAccount;
import com.woniuxy.userapp.infra.model.mapper.model.Venue;
import com.woniuxy.userapp.service.VenueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.userapp.service.dto.ChangeVenueMoneyDto;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2022-08-03
 */
@Service
public class VenueServiceImpl extends ServiceImpl<VenueMapper, Venue> implements VenueService {

    //根据场馆id修改余额
    @Override
    public void changeVenueMoney(ChangeVenueMoneyDto changeVenueMoneyDto) {
//        Venue venue = baseMapper.selectOne(new QueryWrapper<Venue>().eq("id", changeVenueMoneyDto.getId()));
//        if(venue == null) throw new UserException(UserExceptionCode.ACCOUNT_NOT_EXISTS);
//        BigDecimal money = venue.getMoney();//账户余额
//        BigDecimal balance = null;//剩下的余额
//        if(changeVenueMoneyDto.getAddOrSub() == 0){//余额减
//            //先判断密码是否正确
//            if(!changeVenueMoneyDto.getPassword().equals(venue.getAlipayCode())) throw new UserException(UserExceptionCode.ACCOUNT_PAYWORD_ERROR);
//            if(changeVenueMoneyDto.getMoneyAmount().compareTo(money) == -1){//用户余额小于课程余额
//                throw new UserException(UserExceptionCode.ACCOUNT_NOT_MONEY);
//            }else{
//                //余额足够
//                balance = money.subtract(changeVenueMoneyDto.getMoneyAmount());
//            }
//        }else if(changeVenueMoneyDto.getAddOrSub() == 1){//余额加
//            balance = money.add(changeVenueMoneyDto.getMoneyAmount());
//        }else{
//            throw new UserException(UserExceptionCode.ACCOUNT_ADDORSUB);
//        }
//        baseMapper.update(null,new UpdateWrapper<Venue>().set("money",balance).eq("id",changeVenueMoneyDto.getId()));
    }
}
